package com.howbuy.test.array;

import java.util.Arrays;

public class ArrayExpand {
	public static void main(String[] args) {
		// 数组变长(扩容)算法!
		int[] ary = { 1, 2, 3 };
		ary = Arrays.copyOf(ary, ary.length + 1);
		ary[ary.length - 1] = 4;
		System.out.println(Arrays.toString(ary));// [1, 2, 3, 4]
		// 字符串连接原理
		char[] chs = { '中', '国' };
		chs = Arrays.copyOf(chs, chs.length + 1);
//		chs[chs.length - 1] = '北';
		chs = Arrays.copyOf(chs, chs.length + 1);
//		chs[chs.length - 1] = '京';
		// 字符数组按照字符串打印
		System.out.println(chs);// 中国北京
		System.out.println();
		System.out.println(chs[3]);
		// 其他数组按照对象打印
		System.out.println(ary);// [I@4f1d0d
	}
}